<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../../css/btnplus.css" />
		<style type="text/css">
			html,body{ background:#fff; }
			.pay_nums_info{ background:#fff; position: relative; padding: 5px 15px;}
			.pay_nums_info::after{ display:block; position: absolute; content: ""; left: 15px; right: 15px; bottom: 0; height: 1px; background-color: #dedede; overflow: hidden; transform: scaleY(0.5);}
			.pay_nums_info label,.pay_nums_list label{ display:block; color:#A5AAAF; font-size:12px; line-height: 32px; }
			.pay_nums_info b{ display: block; font-size: 35px; color: #333; line-height: 60px; height: 60px; overflow: hidden;}
			.pay_nums_info p{ font-size:35px; display:block;height:50px; border:0px blue solid;content:".";color: #333; line-height: 65px;}

			.pay_nums_list{ background:#fff; padding: 0 15px 2.5px;}
			.pay_nums_list li{ position: relative; padding: 0; }
			.pay_nums_list img{ width:28px; margin-right: 12.5px;}
			.pay_nums_list h4{ display:block; font-size: 14px; color: #3262F1; font-weight: 400; line-height: 32px;}
			
			.login{ background:#fff; padding: 2px 0px; }
			.login h2{ display:block; color: #121212; font-size: 30px; line-height: 37.5px;}
			.login .form{ padding-top: 0;}
			.login .text_info{ position :relative; padding:0 13px;}
			.login .text_info::after{ display:block; position:absolute; content: ""; left: 0; right: 0; bottom: 0; height: 1px; overflow: hidden; background-color: #dedede; transform: scaleY(0.5);}
			.login .text_info label{
				height: 25px;
				text-align: justify;
				width: 75px;
				display: block;
				text-align-last: justify;
				vertical-align: middle;
				font-size: 15px; 
				color: #666; 
				padding-right: 15px;
				
			}
			.login .text_info label:after{
				display:inline-block;
				content:'';
				overflow:hidden;
				width: 75px;
				height: 0;		
			}
			.login .text_info input{ display:block; border: 0; width: 100%; font-size: 15px; color: #333; padding: 15px 0; text-align: right; background-color: transparent; }
			.login .text_info label1{ display:block; width:75px; border:1px red solid; font-size: 15px; color: #121212; padding-right: 0;}
			
			.login .text_info1{ position :relative;}
			.login .text_info1::after{ display:block; position:absolute; content: ""; left: 0; right: 0; bottom: 0; height: 0px; overflow: hidden; background-color: #dedede; transform: scaleY(0.5);}
			.login .text_info1 label{ display:block; font-size: 15px; color: #121212; padding-right: 15px;}
			.login .text_info1 button{ display:block; border: 0; background-color: transparent; border-radius: 0; font-size: 12px; color: #121212; height: 45px; margin-bottom: 5px;}
			.login .btns{ padding-top: 5px;}
			.btn{ display:block; border: 0; background-color: #7dc3e8; width: 100%; height: 44px; font-size: 15px; color: #fff; border-radius: 4px;}
			.login .btns a{ display:block; margin-top: 15px; width: 100%; height: 44px; box-sizing: border-box; border: 1px #dedede solid; border-radius: 4px; text-align: center; line-height: 43px; font-size: 15px; color: #121212;}
			.login .btns a:active{ display:block; background-color: #3262F1; margin-top: 15px; width: 100%; height: 44px; box-sizing: border-box; border: 0; border-radius: 4px; text-align: center; line-height: 43px; font-size: 15px; color: #fff;}
			.login h4{ display: block; font-size: 14px; font-weight: 600; color: #333; line-height: 50px; padding:0 13px;}
			
			.display-none { visibility:hidden; }
			.display-show { display:inline; }
			.disable-btn { color:#ccc !important; }
			
			.m_cell_hd1 { display: table-cell; height: 52px; line-height:52px;overflow: hidden;}
			.line5 { display:block; content: ""; height:10px; background:#f5f5f5; }
			
			.pay_btn{ padding: 15px 15px;}
			.pay_btn .btn{ background-color:#3262F1;}
			.footer { color:#999; font-size:12px; padding:5px 10px 0px;  }
		</style>
	</head>
	<body>
		<!--支付保证金start-->
		<div class="pay_nums_info">
			<ul>
				<li class="m_cell_hd"><b>￥</b></li>
				<li class="m_cell_ft m_cell_primary"><p id="iptmoney"></p></li>
			</ul>
		</div>
		<div class="pay_nums_list">
			<ul>
				<li>
					<div class="m_cell_hd m_cell_primary"><label id="mymoneylbl">当前余额：¥</label></div>
					<div class="m_cell_ft"><h4 tapmode onclick="txall();">全部提现</h4></div>
				</li>
			</ul>
		</div>
		<div class="line5"></div>
		<div class="login">
			<h4 class="header_01">银行卡信息</h4>
			<ul class="form">
				<li class="text_info">
					<div class="m_cell_hd"><label>持卡人</label></div>
					<div class="m_cell_ft m_cell_primary"><input type="text" name="txrealname" class="limitinput" limit-num="10" id="txrealname" value="" placeholder="请输入持卡人姓名" /></div>
					
				</li>
				<li class="text_info">
					<div class="m_cell_hd"><label>银行卡号</label></div>
					<div class="m_cell_ft m_cell_primary"><input type="number" name="bankcard" class="limitinput" limit-num="20" id="bankcard" value="" placeholder="请输入银行卡号" /></div>
					
				</li>
				<li class="text_info">
					<div class="m_cell_hd"><label>银行</label></div>
					<div class="m_cell_ft m_cell_primary"><input type="text" name="bankname" class="limitinput" limit-num="30" id="bankname" value="" placeholder="请输入开户银行" /></div>
					
				</li>
			</ul>
			<div class="footer">提示：提现申请后24小时左右到账</div>
		</div>
		<div class="pay_btn">
			<button class="d_btn" id="login-btn" tapmode onclick="tixian();">申请提现</button>
		</div>
		<div 
		
		<!--支付保证金end-->
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	
	<script type="text/javascript">
		var inputs = []; //定义键盘控件名及对应键盘ID
		var UIInput;
		var keyboardId = 0;//当前键盘ID
		var moneykeyboardId = 0;//当前金额键盘ID
		var cardkeyboardId = 0;//当前卡号键盘ID
		var paymoney = 0; //充值金额
		apiready = function() {
			api.parseTapmode();
			getJsonFromAPI();
			UIInput = api.require('UIInput');
			fnInitUIInput();
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					$api.text($api.byId('mymoneylbl'),'当前余额：¥'+userinfo.credit);
					
				}
			});
			api.addEventListener({
                name: 'navitembtn'
            }, function(ret, err) {
                if (ret.type == 'left') {
					api.closeWin({
					});
                }
            });
			api.addEventListener({
				name : 'reloadpage'
			}, function(ret, err) {
				getJsonFromAPI();				
			});
			
			var flag = false
			var inputs = $api.domAll('.limitinput');
			for (var i = 0; i < inputs.length; i++) {
				inputs[i].oninput = function() {
					var limitnum = $api.attr(this,'limit-num');
					setTimeout(() => {
						if (!flag){
							var len = this.value.length;
							if(this.value.length > limitnum)
							{
								this.value = this.value.substr(0,limitnum);
							}
							if($api.attr(this,'id') == 'sendaddress') {
								$api.text($api.byId("tishimsg1"),len+'/30');
							}
							else if($api.attr(this,'id') == 'destaddress') {
								$api.text($api.byId("tishimsg2"),len+'/30');
							}
						}
					}, 0);
				}
			}
			document.addEventListener('compositionstart', function(e) {
				flag = true;
			});
			document.addEventListener('compositionend', function(e) {
				flag = false;
			});
		}
		function getJsonFromAPI() {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/tixian',
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						//hideloading();
						if (ret) {
							//UIInput.value({
								//id: cardkeyboardId,
								//msg: ret.bankcard
							//});
							$api.val($api.byId('txrealname'),ret.txrealname);
							$api.val($api.byId('bankcard'),ret.bankcard);
							$api.val($api.byId('bankname'),ret.bankname);
							
							
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								console.log(JSON.stringify(err));
								toast('网络异常');
							}
						}
					});
				}
			});
		}
		function selPay(obj) {
			hideInput();
			paytype = $api.attr(obj,'data-paytype');
			var liList = document.getElementById("paylist").children;
			for (var i = 0; i < liList.length; i++) {
				$api.removeCls(liList[i], 'on')
			}
			$api.toggleCls(obj,'on');
			
		}
		function txall() {
			//提现全部
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					UIInput.value({
						id: moneykeyboardId,
						msg: userinfo.credit
					});
					paymoney = userinfo.credit;
				}
			});
		}
		function tixian() {
			var txrealname = $api.val($api.byId('txrealname')).trim();
			var bankcard = $api.val($api.byId('bankcard')).trim();
			var bankname = $api.val($api.byId('bankname')).trim();
			if($api.cssVal($api.byId('login-btn'),'opacity')!=1)
			{
				return false;
			}
			if(paymoney==0)
			{
				toast("请输入提现金额");
				return false;
			}
			if(txrealname=='')
			{
				toast("请输入持卡人姓名");
				return false;
			}
			if(bankcard=='')
			{
				toast("请输入银行卡账号");
				return false;
			}
			if(bankname=='')
			{
				toast("请输入银行名称");
				return false;
			}
			
			showbtnloading('login-btn');
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/credit',
						method: 'post',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						},
						data: {
							values: {
								paymoney: paymoney,
								txrealname: txrealname,
								bankcard: bankcard,
								bankname: bankname
							}
						}
					}, function(ret, err) {
						if (ret) {
							api.sendEvent({
								//通知更新积分
								name : 'updatecredit'
							});
							openAlert();
						}
						else
						{
							console.log(JSON.stringify(err));
							toast(err.body.error);
						}
						hidebtnloading('login-btn','申请提现');
					});
				}
			});
		}
		function openAlert()
		{
			var icon = 'sucess.png';
			var title = '已提交';
			var msg = '等待工作人员审核中';
			var winname = 'mymoney_win';
			var btntxt = '返回';
			var param = {
				icon: icon,
				title: title,
				msg: msg,
				btntxt: btntxt,
				winname: winname,
			};
			openNavWin('#ddd','noheadmsg_win','../public/noheadmsg_frm.html','提现申请',false,true,false,[],param);
		}
		function fnInitUIInput(){
			//计算位置
			var keytype = 'number';
			if (api.systemType == "ios") {
				keytype = 'decimal';
			}
			openUIinput('iptmoney','请输入提现金额',5,false,15,keytype,'text');
			//openUIinput('txrealname','请输入持卡人姓名',1,false,13,'default','text');
			//openUIinput('bankcard','请输入银行卡账号',1,false,15,'number','text');
		}
		function hideInput(){
			//隐藏键盘
			UIInput.closeKeyboard({
				id: keyboardId
			});
		}
		function openUIinput(domid,placeholder_str,top,isfocus,fontsize,keyboardType,inputType){
			//打开UIinput
			var password = $api.byId(domid);
			var password_rect = $api.offset(password);
			UIInput.open({
				rect: {
					x: password_rect.l,
					y: password_rect.t+top,
					w: password_rect.w,
					h: password_rect.h -2
				},
				styles: {
					bgColor: '#fff',
					size: fontsize,
					color: '#000',
					placeholder: {
						color: '#ccc'
					}
				},
				autoFocus: isfocus,
				maxRows: 1,
				placeholder: placeholder_str,
				keyboardType: keyboardType,
				inputType: inputType,
				fixedOn: api.frameName,
				fixed: false
			}, function(ret) {
				if (ret) {
					//keyboardId = ret.id;
					UIInput.addEventListener({
						id: ret.id,
						name : 'becomeFirstResponder'
					}, function() {
						//获得焦点
						//password.focus();
						keyboardId = getjsonbykey(inputs,domid);  
					});
					if (ret.eventType == 'show') {
						inputs.push({name:domid, value:ret.id});
						if(domid == 'iptmoney')
						{
							moneykeyboardId = ret.id;
						}
						else if(domid == 'bankcard')
						{
							cardkeyboardId = ret.id;
						}
					}
					else if (ret.eventType == 'change') {
						keyboardId = ret.id;
						UIInput.value({
								id: ret.id,
								//msg : '设置输入框的值'
						}, function(ret, err) {
							if (ret) {
								if(domid == 'iptmoney')
								{
									paymoney = ret.msg;
								}
								else
								{
									$api.val(password,ret.msg);
								}
							} else {
								//alert(JSON.stringify(err));
							}
						});
					}
				}
			});
			
		}
	</script>
</html>